// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class RESPONSE_RRA_O02 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 PATIENT",12)]
  	    [HL7Field(HL7Version.v23, 12, HL7Repeat.False, HL7Required.False,"PATIENT_RRA_O02")]
	    public PATIENT_RRA_O02 PATIENT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("20 ORDER",20)]
  	    [HL7Field(HL7Version.v23, 20, HL7Repeat.True, HL7Required.True,"ORDER_RRA_O02")]
	    public ORDER_RRA_O02[] ORDER {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PATIENT = ProcessGroup<PATIENT_RRA_O02>(availableData, options, "PATIENT");
			ORDER = ProcessGroupArray<ORDER_RRA_O02>(availableData, options, "ORDER");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			PATIENT_RRA_O02 testPATIENT_RRA_O02 = new PATIENT_RRA_O02();
			bool grpCCPATIENT_RRA_O02 = (testPATIENT_RRA_O02.CanConsume(availableData, options));
			if (IsRequired("PATIENT", options.Version) || grpCCPATIENT_RRA_O02) {
				return grpCCPATIENT_RRA_O02;
			}
			ORDER_RRA_O02 testORDER_RRA_O02 = new ORDER_RRA_O02();
			bool grpCCORDER_RRA_O02 = (testORDER_RRA_O02.CanConsume(availableData, options));
			if (IsRequired("ORDER", options.Version) || grpCCORDER_RRA_O02) {
				return grpCCORDER_RRA_O02;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "RESPONSE";
			}
        }

        static RESPONSE_RRA_O02() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(RESPONSE_RRA_O02));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PATIENT != null) {
			string segmentValue = PATIENT.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ORDER != null && ORDER.Length > 0) {
			for (int i = 0; i < ORDER.Length; i++) {
				string segmentValue = ORDER[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

